from shapely import wkt
import numpy as np
from shapely.geometry import Point
from sqlalchemy import create_engine
import pandas as pd
import geopandas as gd


def get_oracle_engine():
    user = 'ehl_sce'
    password = 'ehl1234'
    ip = '10.2.111.203'
    port = '1521'
    instance = 'orcl'
    engine_str = 'oracle://%s:%s@%s:%s/%s' % (user, password, ip, port, instance)
    engine = create_engine(engine_str, encoding='utf-8')
    return engine


def cal_dis():
    geom = [Point(xy) for xy in zip([116.989727,117.042058 ], [36.668945,36.67505])]
    gdf = gd.GeoDataFrame(geometry=geom, crs={'init': 'epsg:4326'})
    gdf.to_crs(epsg=3310, inplace=True)
    l = gdf.distance(gdf.shift())
    print(l)
    return

    df = pd.read_sql('select * from t_sce_seginfo_test ', get_oracle_engine())
    geom = df['shape'].apply(wkt.loads).values
    gdf = gd.GeoDataFrame(df.copy(),geometry=geom, crs={'init': 'epsg:4326'})
    gdf.to_crs(epsg=3857, inplace=True)
    df['roadseglength'] = gdf.length
    df['roadseglength'] = np.round(df['roadseglength'], 3)
    df['roadwidth'] = df['roadwidth'].astype('float')
    df.to_sql('t_sce_seginfo_test', get_oracle_engine(), if_exists='append', index=False)
    pass


if __name__ == '__main__':
    cal_dis()
